package com.oa.pm.service.impl;

import com.joneying.common.annotation.CommonService;
import com.oa.core.PageResult;
import com.oa.pm.dto.TopicDetailsListDTO;
import com.oa.pm.entity.Topic;
import com.oa.pm.mapper.TopicMapper;
import com.oa.pm.service.ITopicService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.oa.pm.vo.TopicDetailsVO;
import com.oa.pm.vo.TopicListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.plugins.Page;
import java.util.List;

/**
 * <p>
 * 题目表 服务实现类
 * </p>
 *
 * @author syb123
 * @since 2019-01-22
 */
@Service
public class TopicServiceImpl extends ServiceImpl<TopicMapper, Topic> implements ITopicService {

    private final TopicMapper topicMapper;

    @Autowired
    public TopicServiceImpl(TopicMapper topicMapper) {
        this.topicMapper = topicMapper;
    }

    @Override
    @CommonService
    public PageResult<Topic> findList(Integer pageNum, Integer pageSize) {
        if(pageNum == null){
            List<Topic> list = topicMapper.findList();
            return new PageResult<>(list);
        }else{
            // 当前页，总条数 构造 page 对象
            Page<Topic> page = new Page<>(pageNum, pageSize);
            //查询
            List<Topic> list = topicMapper.findList(page);
            return new PageResult<>(list);
        }
    }

    /**
    * 根据id查询
    */
    @Override
    @CommonService
    public Topic findTopicById(String id){
        return topicMapper.findById(id);
    }

    @Override
    public PageResult<TopicListVO> findTopicListByItemBankId(Integer pageNum, Integer pageSize, String itemBankId) {
        Page page = new Page(pageNum, pageSize);
        return new PageResult<>(topicMapper.findTopicListByItemBankId(page, itemBankId), page);
    }

    @Override
    public List<TopicDetailsVO> findTopicDetailsList(TopicDetailsListDTO topicDetailsListDTO) {
        return topicMapper.findTopicDetailsList(topicDetailsListDTO);
    }

}
